package com.xushu.query;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.*;

public class SingleThreadQuery {
    private static final int TIMEOUT_MS = 200;


    // 1. Future
    public static void main(String[] args) throws InterruptedException, ExecutionException, TimeoutException {

        long begin = System.currentTimeMillis();
        // 查询
        List<String> finalResult = fetchDataFromAPI();
        long end = System.currentTimeMillis();
        // 输出最终结果
        System.out.println("result size: " + finalResult);
        System.out.println("耗时: " + (end-begin));

    }

    // 模拟调用接口的方法
    private static List<String> fetchDataFromAPI() throws InterruptedException {
        // 模拟接口调用延迟200ms
        Thread.sleep(200);
        List<String> data = new ArrayList<>();
        for (int i = 0; i < 200; i++) {
            data.add("Data " + i);
        }
        return data;
    }
}